<?php 
	$product_details = $this->product_details ;
	$list_images = $this->list_image ;
	$methods = $this->methods ;
	$qty = $this->qty ;
?>
<script>
	var user_points = '<?php echo $this->p_o_u ; ?>';
	
	jQuery(document).ready(function() {
		jQuery(".header").hide();
		jQuery(".footer").hide();
		jQuery(".menu").hide();

		jQuery("#ajax-loading-ck2").find("input").keydown(function(event) {
	        // Allow: backspace, delete, tab, escape, and enter
	        if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 || 
	             // Allow: Ctrl+A
	            (event.keyCode == 65 && event.ctrlKey === true) || 
	             // Allow: home, end, left, right
	            (event.keyCode >= 35 && event.keyCode <= 39)) {
	                 // let it happen, don't do anything
	                 return;
	        }
	        else {
	            // Ensure that it is a number and stop the keypress
	            if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
	                event.preventDefault(); 
	            }   
	        }
	    });
	    
		jQuery(".point2").click(function() {
			var qty = jQuery(this).attr('qty');
			var points = parseInt(jQuery(this).attr('rel1'));

			jQuery(qty).attr('rel2', 'p');
			var total_points = parseInt(jQuery(qty).val()) * points;

			if (parseInt(user_points) - total_points < 0) {
				jQuery(qty).val("0");
				jQuery(dest).html("");
			} else {
				var dest = jQuery(this).attr('destination');
				jQuery(dest).html("<br/><br/><font size='5' color='blue'>" + total_points + " pts </font> ");
			}
		});
		
		jQuery(".money2").click(function() {
			var qty = jQuery(this).attr('qty');
			var points = parseInt(jQuery(this).attr('rel1'));
			var money = parseInt(jQuery(this).attr('rel2'));

			jQuery(qty).attr('rel2', 'pm');
			var total_points = parseInt(jQuery(qty).val()) * points;
			var total_money = parseInt(jQuery(qty).val()) * money;
			
			if (parseInt(user_points) - total_points < 0) {
				jQuery(qty).val("0");
				jQuery(dest).html("");
			} else {
				var dest = jQuery(this).attr('destination');
				jQuery(dest).html("<br/><font size='5' color='blue'>" + total_points + " pts </font> <hr /> <font size='5'color='red'>" + total_money + " vnd</font>");
			}
		});

		// clear cart
		jQuery(".moneyDelete").click(function() {
			var products = "";
			var product_delete_id = jQuery(this).attr('rel');
			jQuery("#ajax-loading-ck2").find("input").each(function() {
				var method = jQuery(this).attr('rel2');
				if (method != '') {
					var product_id = jQuery(this).attr('rel1');
					var qty = jQuery(this).val();
					if (product_delete_id != product_id) {
						products += "&product[]=" + method + ";" + product_id + ";" + qty;
					}
				}
			});

			var url = "<?php echo JRoute::_("index.php?option=com_wrd&view=redemption&layout=editcart")?>"  + products;
			jQuery.get(url, function(data) {
				  jQuery.facebox(data);
			});
		});
		
		// clear cart
		jQuery("#clearCart3").click(function() {
			var url = "<?php echo JRoute::_("index.php?option=com_wrd&view=redemption&layout=confirm")?>";
			jQuery.get(url, function(data) {
				  jQuery.facebox(data);
			});
		});

		// submit cart
		jQuery("#submitCart3").click(function() {
			var products = "";
			jQuery("#ajax-loading-ck2").find("input").each(function() {
				var method = jQuery(this).attr('rel2');
				if (method != '') {
					var product_id = jQuery(this).attr('rel1');
					var qty = jQuery(this).val();
	
					products += "&product[]=" + method + ";" + product_id + ";" + qty;
				}
			});

			var url = "<?php echo JRoute::_("index.php?option=com_wrd&view=redemption&layout=editcart")?>"  + products;
			jQuery.get(url, function(data) {
				  jQuery.facebox(data);
			});
		});
	});
</script>
<h2 class="arrow_left_bg">CONFIRMATION DETAILS</h2>
<div id="ajax-loading-ck2">
		<div class="selectProvider">
			<a name="listTop"></a>
			<div class="tools top">
				<table width="100%" cellspacing="0" cellpadding="0">
					<tbody>
						<tr>
							<td width="160"><span><h2><?php echo $this->cat_name ; ?></h2></span></td>
							<td width="145"></td>
						</tr>
					</tbody>
				</table>
			</div>
				<div class="SPList">
					<div id="selectad" class="selectad s1 "></div>
					<?php $i=0; $total_point=0;$total_cash=0;
							foreach($product_details as $product):
								$images = $list_images[$product->id];
					?>
					<div class="sp">
						<ul style="list-style-type: none;">
							<li class="sp-image">
								<div class="image">
									<a href="index.php?option=com_wrd&view=redemption&layout=product&cid=<?php echo $product->cat_id ; ?>&pid=<?php echo $product->id ; ?>&Itemid=126">
										<img src="wrd/thumb/<?php echo $images->file_name ;?>" class="productImage" alt="Product Details">
									</a>
								</div>
							</li>
							<li class="sp-id">
								<p class="sp-name">
									<a class="title" href="index.php?option=com_wrd&view=redemption&layout=product&cid=<?php echo $product->cat_id ; ?>&pid=<?php echo $product->id ; ?>&Itemid=126">
										<?php echo $product->products_name ; ?>
									</a>
								</p>
								<span class="sp-expertise">
									<?php 
                                                if(!empty($product->point)){
                                                    echo 'Normal: '.$product->point.' Points' ; 
                                                }
                                    ?>        
								</span>
								<span class="sp-expertise">
									<?php 
                                                if(!empty($product->pointx)){ 
                                                    echo "Fast Track: ".$product->pointx ;  ?> Points + <?php echo $product->cash ; ?> VND<?php 
                                                } 
                                     ?>
								</span>
								<?php if(!empty($product->quantity)): ?> 
				                    <span style="padding-left: 1px;padding-top: 20px;">
										<input type="text" value="<?php echo $qty[$product->id];?>" style="width: 15px" rel1="<?php echo $product->id ; ?>" rel2="<?php echo $methods[$product->id] ; ?>" id="q2ty<?php echo $i;?>">
									</span>
									<button class="button btn-green point2" type="button" rel1="<?php echo $product->point ; ?>" rel2="<?php echo $product->cash ; ?>" qty="#q2ty<?php echo $i;?>" destination="#short2Desc<?php echo $i;?>">
										<span><span>Redeem by point</span></span>
									</button>
									<button class="button btn-green money2" type="button" rel1="<?php echo $product->pointx ; ?>" rel2="<?php echo $product->cash ; ?>" qty="#q2ty<?php echo $i;?>" destination="#short2Desc<?php echo $i;?>">
										<span><span>point and cash</span></span>
									</button>
									<button class="button btn-green moneyDelete" type="button" rel="<?php echo $product->id;?>">
										<span><span>Delete</span></span>
									</button>
									<br/>
				                <?php else: ?>
				                    <li class="sp-id">
										<span class="out_of_stock"><i>Out of stock</i></span>
									</li>
				                <?php endif; ?>
							</li>
						</ul>
						<div id="short2Desc<?php echo $i;?>" style="position: absolute;margin-left: 500px;">
							<br/>
							<font size='5' color='blue'>
								<?php 
                                	if($methods[$product->id] == 'p') {
                                		echo $product->point * $qty[$product->id];
                                	}
                                ?>
                                <?php 
                                	if($methods[$product->id] == 'pm') {
                                    	echo $product->pointx * $qty[$product->id];
                                	}
                                ?>pts
							</font>
							<hr />
							<font size='5'color='red'>
								<?php 
                                	if($methods[$product->id] == 'pm') {
                                    	echo $product->cash * $qty[$product->id]; 
                                ?> vnd
                                <?php 
                                	}
                                ?>
							</font>
						</div>
					</div>
					<?php $i++;
							endforeach;
					?>
				</div>
			<div class="sp-join">
				<button id="submitCart3">Finish</button>
				<a href="###" style="float: right; margin-top: 2px">&nbsp;</a>
				<button id="clearCart3">Cancel</button>
			</div>
		</div>
</div>